/**
 * 报关单字段提取相关类型定义
 */

// 字段提取规则
export interface FieldRule {
  field: string;
  type: string;
  description: string;
  required?: boolean;
  example?: string;
  items?: FieldRule[];
}

// 商品明细项
export interface ProductItem {
  项号?: string;
  商品编号?: string;
  商品名称及规格型号?: string;
  数量及单位?: string;
  "单价/总价/币制"?: string;
  原产国?: string;
  最终目的国?: string;
  境内目的地?: string;
  征免?: string;
}

// 提取的字段数据
export interface ExtractedFields {
  进口日期?: string;
  申报日期?: string;
  境内收货人?: string;
  进境关别?: string;
  境外发货人?: string;
  运输方式?: string;
  运输工具名称及航次号?: string;
  提运单号?: string;
  货物存放地点?: string;
  消费使用单位?: string;
  监管方式?: string;
  征免性质?: string;
  启运港?: string;
  "贸易国（地区）"?: string;
  "启运国（地区）"?: string;
  经停港?: string;
  入境口岸?: string;
  包装种类?: string;
  成交方式?: string;
  运费?: string;
  保费?: string;
  自报自缴?: string;
  件数?: string;
  "毛重(千克)"?: string;
  "净重(千克)"?: string;
  随附单证及编号?: string;
  标记唛码及备注?: string;
  项目?: ProductItem[];
  特殊关系确认?: string;
  价格影响确认?: string;
  支付特许权使用费确认?: string;
  公式定价确认?: string;
  报关人员证号?: string;
  报关人员?: string;
  报关人员电话?: string;
  海关批注及签章?: string;
  申报单位?: string;
  报关专用章?: string;
  报单签章?: string;
}

// 单个字段提取结果
export interface FieldExtractionResult {
  field: string;
  success: boolean;
  raw_content?: string;
  extracted_data?: any;
  error?: string;
  request_id?: string;
  chat_id?: string;
  conversation_id?: string;
}

// API响应格式
export interface ApiResponse<T = any> {
  success: boolean;
  message: string;
  data?: T;
  error?: string;
}

// 字段提取API响应
export interface ExtractionResponse {
  success: boolean;
  message: string;
  data: {
    upload_summary: {
      total_files: number;
      successful_uploads: number;
      upload_details: Array<{
        file_id: string;
        filename: string;
        success: boolean;
      }>;
    };
    extraction_summary: {
      total_fields: number;
      successful_fields: number;
      failed_fields: number;
    };
    excel_file: string;
    fields_data: Record<string, any>;
    raw_contents?: Record<string, string>;  // 智能体原始content内容
    errors?: any;
  };
}

// 上传文件信息
export interface UploadFile {
  uid: string;
  name: string;
  status: 'uploading' | 'done' | 'error';
  originFileObj?: File;
  percent?: number;
}

// 字段分组
export interface FieldGroup {
  title: string;
  fields: Array<{
    label: string;
    key: keyof ExtractedFields;
    span?: number;
  }>;
}

